home *** CD-ROM | disk | FTP | other *** search
- VERSION 4.00
- Begin VB.Form PerspectiveForm
- Appearance = 0 'Flat
- BackColor = &H00C0C0C0&
- Caption = "Perspective Projection"
- ClientHeight = 5670
- ClientLeft = 1770
- ClientTop = 900
- ClientWidth = 5310
- BeginProperty Font
- name = "MS Sans Serif"
- charset = 0
- weight = 700
- size = 8.25
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- ForeColor = &H80000008&
- Height = 6360
- KeyPreview = -1 'True
- Left = 1710
- LinkTopic = "Form1"
- ScaleHeight = 5670
- ScaleWidth = 5310
- Top = 270
- Width = 5430
- Begin VB.CheckBox ClipCheck
- Caption = "Clip"
- Height = 255
- Left = 720
- TabIndex = 1
- Top = 5400
- Width = 735
- End
- Begin VB.PictureBox Pict
- AutoRedraw = -1 'True
- Height = 5295
- Left = 0
- ScaleHeight = -14
- ScaleLeft = -7
- ScaleMode = 0 'User
- ScaleTop = 7
- ScaleWidth = 14
- TabIndex = 0
- Top = 0
- Width = 5295
- End
- Begin VB.Label Label1
- Caption = "Distance to origin:"
- Height = 255
- Index = 0
- Left = 2160
- TabIndex = 3
- Top = 5400
- Width = 1575
- End
- Begin VB.Label RLabel
- BorderStyle = 1 'Fixed Single
- Height = 255
- Left = 3720
- TabIndex = 2
- Top = 5400
- Width = 855
- End
- Begin VB.Menu mnuFile
- Caption = "&File"
- Begin VB.Menu mnuFileExit
- Caption = "E&xit"
- End
- End
- Attribute VB_Name = "PerspectiveForm"
- Attribute VB_Creatable = False
- Attribute VB_Exposed = False
- Option Explicit
- ' Location of viewing eye.
- Dim EyeR As Single
- Dim EyeTheta As Single
- Dim EyePhi As Single
- Const Dtheta = PI / 20
- Const Dphi = PI / 20
- Const Dr = 1
- ' Location of focus point.
- Const FocusX = 0#
- Const FocusY = 0#
- Const FocusZ = 0#
- Dim Projector(1 To 4, 1 To 4) As Single
- ' *******************************************************
- ' Rotate the points in the cube and draw the cube.
- ' *******************************************************
- Private Sub DrawData(pic As Object)
- Dim i As Integer
- Dim x1 As Single
- Dim y1 As Single
- Dim z1 As Single
- Dim x2 As Single
- Dim y2 As Single
- Dim z2 As Single
- Dim do_clip As Boolean
- Dim draw_seg As Boolean
- ' Prevent overflow errors when drawing lines
- ' too far out of bounds.
- On Error Resume Next
- ' Transform the points.
- TransformAllDataFull Projector
- ' Display EyeR.
- RLabel.Caption = Format(EyeR, "0.000")
- ' Draw the points.
- pic.Cls
- do_clip = (ClipCheck.value = vbChecked)
- draw_seg = True
- For i = 1 To NumSegments
- If do_clip Then
- z1 = Segments(i).fr_tr(3)
- z2 = Segments(i).to_tr(3)
- ' Don't draw if either point is farther
- ' from the focus point than the center of
- ' projection (which is distance EyeR away).
- draw_seg = (z1 < EyeR And z2 < EyeR)
- End If
- If draw_seg Then
- x1 = Segments(i).fr_tr(1)
- y1 = Segments(i).fr_tr(2)
- x2 = Segments(i).to_tr(1)
- y2 = Segments(i).to_tr(2)
- pic.Line (x1, y1)-(x2, y2)
- End If
- Next i
- pic.Refresh
- End Sub
- Private Sub ClipCheck_Click()
- DrawData Pict
- Pict.SetFocus
- End Sub
- Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
- Select Case KeyCode
- Case vbKeyLeft
- EyeTheta = EyeTheta - Dtheta
-
- Case vbKeyRight
- EyeTheta = EyeTheta + Dtheta
-
- Case vbKeyUp
- EyePhi = EyePhi - Dphi
-
- Case vbKeyDown
- EyePhi = EyePhi + Dphi
-
- Case Else
- Exit Sub
- End Select
- m3PProject Projector, m3Perspective, EyeR, EyePhi, EyeTheta, FocusX, FocusY, FocusZ, 0, 1, 0
- DrawData Pict
- End Sub
- Private Sub Form_KeyPress(KeyAscii As Integer)
- Select Case KeyAscii
- Case Asc("+")
- EyeR = EyeR + Dr
-
- Case Asc("-")
- EyeR = EyeR - Dr
-
- Case Else
- Exit Sub
- End Select
- m3PProject Projector, m3Perspective, EyeR, EyePhi, EyeTheta, FocusX, FocusY, FocusZ, 0, 1, 0
- DrawData Pict
- End Sub
- Private Sub Form_Load()
- ' Initialize the eye position.
- EyeR = 10
- EyeTheta = PI * 0.2
- EyePhi = PI * 0.05
- ' Initialize the projection transformation.
- m3PProject Projector, m3Perspective, EyeR, EyePhi, EyeTheta, FocusX, FocusY, FocusZ, 0, 1, 0
- ' Create the data.
- CreateData
- ' Project and draw the data.
- DrawData Pict
- End Sub
- Sub CreateData()
- Const WID = 1
- Dim x As Single
- Dim y As Single
- Dim z As Single
- ' Create the cubes.
- For x = -3 To 3 Step 6
- For y = -3 To 3 Step 6
- For z = -3 To 3 Step 6
- MakeSegment x - WID, y - WID, z - WID, x - WID, y - WID, z + WID
- MakeSegment x - WID, y - WID, z + WID, x - WID, y + WID, z + WID
- MakeSegment x - WID, y + WID, z + WID, x - WID, y + WID, z - WID
- MakeSegment x - WID, y + WID, z - WID, x - WID, y - WID, z - WID
- MakeSegment x + WID, y - WID, z - WID, x + WID, y - WID, z + WID
- MakeSegment x + WID, y - WID, z + WID, x + WID, y + WID, z + WID
- MakeSegment x + WID, y + WID, z + WID, x + WID, y + WID, z - WID
- MakeSegment x + WID, y + WID, z - WID, x + WID, y - WID, z - WID
- MakeSegment x - WID, y - WID, z - WID, x + WID, y - WID, z - WID
- MakeSegment x - WID, y - WID, z + WID, x + WID, y - WID, z + WID
- MakeSegment x - WID, y + WID, z + WID, x + WID, y + WID, z + WID
- MakeSegment x - WID, y + WID, z - WID, x + WID, y + WID, z - WID
- Next z
- Next y
- Next x
- End Sub
- Private Sub mnuFileExit_Click()
- Unload Me
- End Sub
-